<%@Page Language="C#" Debug=true%>
<%@ Import Namespace="System.IO" %>

<script runat=server>

	ArrayList movieList;
	string BestMovieOfAllTime;	

	protected void Page_Load( object sender, EventArgs e )
	{

		movieList = new ArrayList();

		movieList.Add("Pulp Fiction");
		movieList.Add("Aliens");
		movieList.Add("The good, the Bad and the Ugly");

		try
		{
			BestMovieOfAllTime = (string)movieList[6];
		}
		catch( ArgumentOutOfRangeException rangeException )
		{
			BestMovieOfAllTime = "argument out of range";
		}

	}

	// Class that implements the comparison logic for the sort

	class MyComparer : IComparer
	{

		public int Compare( object x, object y )
		{
			
			if ( x is string && y is string )
			{
				IComparable ic;
				int compareResult;

				ic = (IComparable) x;
				compareResult = ic.CompareTo( y );

				if ( compareResult != 0 )
					compareResult = compareResult * -1;

				return compareResult;
			}
			else
			{
				throw new Exception("Simple comparer can only compair strings");
			}
			return -1;
		}
	}


</script>

<form runat=server>

<h3>Movies List</h3>

<%

	if ( movieList.Count != 0 ) 
	{
		Response.Write("<table>");
		Response.Write("<tr bgcolor=cornflowerblue>");
		Response.Write("<td>Movie Name");
		Response.Write("</tr>");

		foreach( string Movie in movieList )
		{
			Response.Write("<tr>");
			Response.Write("<td>" + Movie );
		}
		Response.Write("</table>");
	}
	else
	{
		Response.Write("<P>There are no movies in the list.");
	}

	Response.Write("<P>The best movie of all time is :" + BestMovieOfAllTime );


	Response.Write("<HR>");

	string[] authors = new string[5] { "Richard", 
									    "Alex","Dave",
										"Karli", "Brian" };
								
	IEnumerator e1;

	e1 = authors.GetEnumerator();
	while( e1.MoveNext() == true )
	{
		Response.Write("<P>" + e1.Current );
	}



	foreach( string author in authors )
	{
		Response.Write("<P>" + author );
	
	}

	// sample 

	Response.Write("<HR>");

	Session["value1"] = "Wrox";
	Session["value2"] = "Press";

	string value;

	value = (string) Session["value1"];
	value = (string) Session["value2"];

	foreach( string s in Session )
	{
		Response.Write("<P>Session key is " + s );
		Response.Write("<P>Session value is " + Session[s] );
	}
Hashtable ourSession;

ourSession = new Hashtable();

ourSession["value1"] = "Wrox";
ourSession["value2"] = "Press";

value = (string) ourSession["value1"];
value = (string) ourSession["value2"];



foreach( string author in authors )
{
	Response.Write("<P>" + author );
}


//C#

int index;

index = Array.IndexOf( authors, "Richard");
if ( index != -1 )
{
	Response.Write("<P>" + authors[index] + " is in the author list");
}

//C#

IList list = (IList) authors;

if ( list.Contains("Richard") == true )
{
	index = list.IndexOf("Richard");
	Response.Write("<P>" + list[index] + " is in the author list");
}

IList movieList2;

movieList2 = new ArrayList();
movieList2.Add("Pulp Fiction");
movieList2.Add("Aliens");

     

%>


</form>

<p style="color:red" id=status EnableViewState=False runat=server />
